package com.hbnu.serializable;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;

/**
 * @author kittychen
 * @since 2025-10-14 11:06
 */
public class SerializableTest {
    public static void main(String[] args) {
        String path = "E:" + File.separator + "2309" + File.separator + "object.txt";
        File file = new File(path);

        ObjectOutputStream outputStream = null;
        try {
            outputStream = new ObjectOutputStream(new FileOutputStream(file));

            Person zhangsan = new Person("张三", 18);
            outputStream.writeObject(zhangsan);
            outputStream.flush();
            System.out.println("序列化成功！！！");
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (outputStream != null) {
                    outputStream.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
